package top.ezzz.tree;

import cn.hutool.core.util.RandomUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;

@Getter
@Setter
public class TwoTreeNode extends TreeNode {
    Integer val;

    TwoTreeNode left, right;


    static int index = 0;

    public static void traverse(TwoTreeNode root) {
        if (root == null) {
            return;
        }

        //中序遍历
        System.out.print(root.val + " ");

        // 前序遍历
        traverse(root.left);
        //后续遍历
        traverse(root.right);
    }

    static ArrayList<Integer> list = new ArrayList<>();

    public static void init(TwoTreeNode treeNode) {
        list.add(RandomUtil.randomInt(2, 25));
        treeNode.val = list.get(list.size() - 1);


        treeNode.left = new TwoTreeNode();
        init(treeNode.left);


        treeNode.right = new TwoTreeNode();
        init(treeNode.right);
    }


    public static void main(String[] args) {
        TwoTreeNode treeNode = new TwoTreeNode();
        init(treeNode);

        TreeNodeShow.show(treeNode);

        traverse(treeNode);
    }


}
